package br.com.caelum.vraptor.util;


import javax.inject.Inject;

import br.com.caelum.vraptor.AroundCall;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.anotations.Restrito;
import br.com.caelum.vraptor.componentes.FuncionarioOn;
import br.com.caelum.vraptor.controller.CarteirasController;
import br.com.caelum.vraptor.interceptor.AcceptsWithAnnotations;
import br.com.caelum.vraptor.interceptor.SimpleInterceptorStack;

@Intercepts
@AcceptsWithAnnotations(Restrito.class)
public class Interceptor {
	
	@Inject
	private FuncionarioOn sessioned;
	@Inject
	private Result result;
	
	@AroundCall
	public void intercept(SimpleInterceptorStack stack){
		if(sessioned.logado()){stack.next();System.out.println("Logado, passou");}
		else{
			result.redirectTo(CarteirasController.class).login();
		}
	}

}
